package com.api.gbhg.zengping.action;

import com.api.gbhg.liwenjun.GBHGConstant;
import com.api.gbhg.liwenjun.VersionFlowUtil;
import com.api.gbhg.luoao.tool.ToolCURD;
import com.api.gbhg.zengping.dao.PropertyManagementCostDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: gbhg-oa
 * @author: Mr.zeng
 * @create: 2021-01-09 11:09
 * 18 重大预算追加统计=====数据同步
 **/
public class BudgetAddStatistics implements Action {
    public static final Logger LOGGER = LoggerFactory.getLogger("gbhg");
    @Override
    public String execute(RequestInfo requestInfo) {
        LOGGER.info("====================================进入重大预算追加统计 Action方法=========================================");
        final String requestid = requestInfo.getRequestid();
        // 同步流程数据到版本表
        Map<String,String> map=new HashMap<>();
        // 预算总金额通过sql语句修改
        RecordSet rs = ToolCURD.selectDetailnanlist(requestInfo, 1);
        double total = 0.00;
        while (rs.next()){
            total = total+rs.getDouble("hjwy");
        }
        map.put("xmmin","xmmc");
        boolean resV = VersionFlowUtil.sysDataToVersion(requestid, requestInfo.getWorkflowid(), GBHGConstant.FlowVersionTableEnum.uf_zdyszjtjb,map);
        //把预算总金额插入到主表中
        boolean up = PropertyManagementCostDao.modifyYszje(requestInfo.getRequestid(), total);
        if(!resV||!up){
            LOGGER.info("============================重大预算追加统计 同步失败,数据同步异常======================================");
            requestInfo.getRequestManager().setMessagecontent("重大预算追加统计表数据异常");
            requestInfo.getRequestManager().setMessageid("1");
            return FAILURE_AND_CONTINUE;
        }
        return SUCCESS;
    }
}
